package com.leadership.entity;

import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.springframework.format.annotation.DateTimeFormat;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.leadership.entity.idm.IdmUser;
import com.leadership.entity.idm.Organization;

/**
 * 
 * @author mohanlan
 *
 */
@Entity
@Table(name = "learning_map_student")
public class LearningMapStudent {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    /** 用户名  */
    private String username;
    
    /** 中文名称 */
    private String usercn;
    
    /** 邮箱  */
    private String email;
    
    private String userstatus;
    
    /** 部门 */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
    @JsonIdentityReference(alwaysAsId=true)
    private Organization organization;
    
    /** 学习地图 */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
    @JsonIdentityReference(alwaysAsId=true)
    private LearningMap learningMap;
    
    /** 职能 */
    private String position;
    
    /**
     * 截止时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date endTime;
    
    private LearningMapStatus status;
    
    private Double overallCompletionRate;
    
    private Double requiredCompletionRate;
    
    private boolean needNotice;
    
    /**
     * 自动新增
     */
    private boolean autoCreate;
    
    /** 是否启用 */
    @Column(name = "is_disabled")
    private boolean disabled;
    
    
    public LearningMapStudent() {
    }
    
    public LearningMapStudent(IdmUser idmUser, Organization organization, LearningMap learningMap, Date endTime) {
        this.learningMap = learningMap;
        this.organization = organization;
        this.email = idmUser.getMail();
        this.usercn = idmUser.getUsercn();
        this.username = idmUser.getAlias();
        this.position = idmUser.getPositionname();
        this.endTime = endTime;
        this.status = LearningMapStatus.PROCESSING;
        this.userstatus = idmUser.getUserstatus();
        this.autoCreate = false;
        this.disabled = false;
    }
    
    public LearningMapStudent(IdmUser idmUser, Organization organization, LearningMap learningMap, Date endTime, boolean needNotice) {
        this.learningMap = learningMap;
        this.organization = organization;
        this.email = idmUser.getMail();
        this.usercn = idmUser.getUsercn();
        this.username = idmUser.getAlias();
        this.position = idmUser.getPositionname();
        this.endTime = endTime;
        this.status = LearningMapStatus.PROCESSING;
        this.userstatus = idmUser.getUserstatus();
        this.disabled = false;
        this.autoCreate = true;
        this.needNotice = needNotice;
    }
    
    /**
     * 
     * @param total
     * @param required
     * @return
     */
    public LearningMapStudent updateGrade(Double total, Double required) {
        this.overallCompletionRate = total;
        this.requiredCompletionRate = required;
        
        return this;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the username
     */
    public String getUsername() {
        return username;
    }

    /**
     * @return the usercn
     */
    public String getUsercn() {
        return usercn;
    }

    /**
     * @return the email
     */
    public String getEmail() {
        return email;
    }

    /**
     * @return the organization
     */
    public Organization getOrganization() {
        return organization;
    }

    /**
     * @return the learningMap
     */
    public LearningMap getLearningMap() {
        return learningMap;
    }

    /**
     * @return the position
     */
    public String getPosition() {
        return position;
    }

    /**
     * @return the endTime
     */
    public Date getEndTime() {
        return endTime;
    }

    public String getUserstatus() {
        return userstatus;
    }

    /**
     * @return the status
     */
    public LearningMapStatus getStatus() {
        return status;
    }
    
    public Double getOverallCompletionRate() {
        return overallCompletionRate;
    }
    
    public Double getRequiredCompletionRate() {
        return requiredCompletionRate;
    }
    
    public boolean isNeedNotice() {
        return needNotice;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param username the username to set
     */
    public void setUsername(String username) {
        this.username = username;
    }

    /**
     * @param usercn the usercn to set
     */
    public void setUsercn(String usercn) {
        this.usercn = usercn;
    }

    /**
     * @param email the email to set
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * @param organization the organization to set
     */
    public void setOrganization(Organization organization) {
        this.organization = organization;
    }

    /**
     * @param learningMap the learningMap to set
     */
    public void setLearningMap(LearningMap learningMap) {
        this.learningMap = learningMap;
    }

    /**
     * @param position the position to set
     */
    public void setPosition(String position) {
        this.position = position;
    }

    /**
     * @param endTime the endTime to set
     */
    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }
    
    public void setUserstatus(String userstatus) {
        this.userstatus = userstatus;
    }

    /**
     * @param status the status to set
     */
    public void setStatus(LearningMapStatus status) {
        this.status = status;
    }
    
    public void setOverallCompletionRate(Double overallCompletionRate) {
        this.overallCompletionRate = overallCompletionRate;
    }
    
    public void setRequiredCompletionRate(Double requiredCompletionRate) {
        this.requiredCompletionRate = requiredCompletionRate;
    }
    
    public void setNeedNotice(boolean needNotice) {
        this.needNotice = needNotice;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }
    
    public boolean isAutoCreate() {
        return autoCreate;
    }
    
    public void setAutoCreate(boolean autoCreate) {
        this.autoCreate = autoCreate;
    }
}
